package com.cat.twoPointerTechnique;

/**
*   @description https://leetcode.cn/problems/longest-turbulent-subarray/
*   @author 曲大人的喵
*   @create 2025/8/8 14:16
*   @since JDK17
*/

public class Solution21 {
    public int maxTurbulenceSize(int[] arr) {
        int ans = 1, n = arr.length - 1, start;
        for (int i = 0; i < n; i++) {
            if (arr[i] == arr[i + 1]) {
                continue;
            }
            start = i++;
            while (i < n && ((long) ((arr[i] - arr[i - 1]) * (arr[i] - arr[i + 1]))) < 0) {
                i++;
            }
            ans = Math.max(ans, i - start + 1);
        }
        return ans;
    }
}
